function  barcode() {
    cordova.plugins.barcodeScanner.scan(
        function (result) {
            if(result.cancelled) {
                return;
            }
            if(result.format != "QR_CODE") {
                alert("二维码不正确");
                return;
            }
            document.getElementById("barcode").innerHTML = result.text;
        },
        function (error) {
            console.log("Scanning failed: " + error);
        },
        {
            "preferFrontCamera" : true,
            "showFlipCameraButton" : true,
            "showTorchButton" : true,
            "disableAnimations" : true,
            "prompt" : "Place a barcode inside the scan area",
            "formats" : "QR_CODE",
            "orientation" : "portrait"
        }
    );
}

function scanBarcode() {
   const defaultOptions = {
       barcodeFormats: {
           Code128: true,
           Code39: true,
           Code93: true,
           CodaBar: true,
           DataMatrix: true,
           EAN13: true,
           EAN8: true,
           ITF: true,
           QRCode: true,
           UPCA: true,
           UPCE: true,
           PDF417: true,
           Aztec: true,
       },
       beepOnSuccess: false,
       vibrateOnSuccess: false,
       detectorSize: 0.6,
       rotateCamera: false,
   };
   cordova.plugins.mlkit.barcodeScanner.scan(
       defaultOptions,
       (result) => {
           // Do something with the data
           document.getElementById("barcode").innerHTML = result.text;
       },
       (error) => {
           // Error handling
       },
   );
}